package com.appbee.cm.client.nav.presenter;

import javax.inject.Inject;

public class NavSelectionBoxPresenter
{
	public interface View
	{
		public void setValue(NavItemWrap value);
	}

	public interface SelectView
	{
		public void setPresenter(NavSelectionBoxPresenter presenter);

		public void show(Object source);

		public void hide();

		public void setSelectedValue(NavItemWrap value);
	}

	private View view;
	private final NavControl navControl;
	private NavItemWrap value = null;
	private final SelectView selectView;

	@Inject
	public NavSelectionBoxPresenter(NavControl navControl, SelectView selectView)
	{
		this.navControl = navControl;
		this.selectView = selectView;
		selectView.setPresenter(this);

	}

	public void setView(View view)
	{
		this.view = view;
	}

	public void setNavIdValue(Long navId)
	{
		value = navControl.getById(navId);
		view.setValue(value);
	}

	public void onSelectClick(Object source)
	{
		selectView.setSelectedValue(value);
		selectView.show(source);
	}

	public void onNavSelected(NavItemWrap selectedObject)
	{
		value = selectedObject;
		view.setValue(selectedObject);
		selectView.hide();
	}

	public NavItemWrap getValue()
	{
		return value;
	}
}
